package handlers

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"net/http"
	"repo-sys/models"
)

func Add(c *gin.Context) {
	name := c.PostForm("name")
	address := c.PostForm("address")
	if address == "" {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "仓库地址不能为空",
		})
		return
	}
	repo := models.Repo{
		Model:   gorm.Model{},
		Name:    name,
		Address: address,
	}
	models.DB.Create(&repo)
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "添加成功",
		"data": repo,
	})
	return
}
